package cc.telecomdigital.tdstock.adapter;

import java.util.List;

import cc.telecomdigital.tdstock.R;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TwoTextColumnItemAdapter extends BaseAdapter
{
	private LayoutInflater			minflater;
	private List<TwoTextColumnHolder>	list;

	public TwoTextColumnItemAdapter(LayoutInflater inflater,
			List<TwoTextColumnHolder> list)
	{
		super();
		this.minflater = inflater;
		this.list = list;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return this.list.size();
	}

	@Override
	public Object getItem(int position)
	{
		return position < this.list.size() ? this.list.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return position < this.list.size() ? this.list.get(position).id : -1l;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		TwoTextColumnHolder commHolder = null;
		if (convertView == null)
		{
			//convertView = minflater.inflate(R.layout.moreitem, null);
			convertView = minflater.inflate(R.layout.two_text_column_item,
					null);
			commHolder = new TwoTextColumnHolder();
			commHolder.left = (TextView) convertView
					.findViewById(R.id.more_item_left);
			commHolder.right = (TextView) convertView
					.findViewById(R.id.more_item_right);

			//synchronize with iphone
			commHolder.left.setTextColor(Color.BLACK);
			commHolder.right.setTextColor(Color.BLACK);
			convertView.setDrawingCacheBackgroundColor(Color.WHITE);

			//synchronize with iphone

			convertView.setTag(commHolder);
		}
		else
		{
			commHolder = (TwoTextColumnHolder) convertView.getTag();
		}
		if (this.list != null && !this.list.isEmpty())
		{
			commHolder.left.setText(this.list.get(position).left.getText());
			commHolder.right
					.setText(this.list.get(position).right.getText());
		}
		return convertView;
	}

}
